package com.ruoyi.web.controller.wlsggk;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.waterdrop.wlsggk.pojo.Dish;
import com.waterdrop.wlsggk.pojo.dto.DishDto;
import com.waterdrop.wlsggk.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wlsggk/Dish")
public class DishController extends BaseController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DishDto dishDto) {
        return toAjax(dishService.insertDishWithMaterial(dishDto));
    }

    /**
     * 获取菜品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Dish Dish) {
        startPage();
        List<com.waterdrop.wlsggk.pojo.Dish> list = dishService.selectDishList(Dish);
        return getDataTable(list);
    }

    /**
     * 根据菜品id查询
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(dishService.selectwlsggkDishWithMaterialById(id));
    }

    /**
     * 删除菜品信息
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dishService.deleteWlsggkDishWithMaterial(ids));
    }


    /**
     * 修改菜品信息
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Dish dish) {
        return toAjax(dishService.updateWlsggkDish(dish));
    }

}

